package com.atguigu.date;
import org.junit.Test;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

/*
DateTimeFormatter:格式化或解析日期、时间
类似于SimpleDateFormat
 */
public class DateTimeFormat {
    @Test
    public void test(){
        //实例化方式: 自定义方式。如:ofPattern("yyyy-MM-dd hh:mm:ss E")
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
        //格式化
        String format = dateTimeFormatter.format(LocalDateTime.now());
        System.out.println(format);
        //解析
        TemporalAccessor accessor = dateTimeFormatter.parse("2022-12-26 00:00:00");
        System.out.println(accessor);
    }
}
